package pack.terrains;

import com.jme.image.Texture.MagnificationFilter;
import com.jme.image.Texture.MinificationFilter;
import com.jme.image.Texture.WrapMode;
import com.jme.math.Vector3f;
import com.jme.scene.Spatial;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;
import com.jme.util.resource.ResourceLocatorTool;
import com.jmex.physics.PhysicsSpace;
import com.jmex.physics.StaticPhysicsNode;
import com.jmex.physics.material.Material;

public class Terrain 
{
	protected StaticPhysicsNode node;
	
	public void createNode(PhysicsSpace space, Spatial tb)
	{
        node = space.createStaticNode();
        node.attachChild(tb);        
        node.setLocalTranslation(0.0f,0.0f,0.0f);
        
        // fisica para o terreno
        node.generatePhysicsGeometry(true);
        node.setMaterial(Material.CONCRETE);
	}
	
	public TextureState getTexture(String texture)
	{
		// adiciona textura ao terreno
        final TextureState wallTextureState = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
        wallTextureState.setTexture( TextureManager.loadTexture( ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, texture), MinificationFilter.NearestNeighborLinearMipMap, MagnificationFilter.NearestNeighbor ) );
        wallTextureState.getTexture().setScale( new Vector3f( 256, 256, 1 ) );
        wallTextureState.getTexture().setWrap( WrapMode.Repeat );
        
        return wallTextureState;
	}
	
	public StaticPhysicsNode getNode(){
		return node;
	}
}
